

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 内容系统 - 文章列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">作者</label>
            <div class="layui-input-inline">
              <input type="text" name="author" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-inline">
              <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
		  <div class="layui-inline">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-inline">
              <select name="label">
                <option value="">请选择分类</option>
                <option value="0">美食</option>
                <option value="1">新闻</option>
                <option value="2">八卦</option>
                <option value="3">体育</option>
                <option value="4">音乐</option>
              </select>
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">文章标签</label>
            <div class="layui-input-inline">
              <select name="label">
                <option value="">请选择标签</option>
                <option value="0">美食</option>
                <option value="1">新闻</option>
                <option value="2">八卦</option>
                <option value="3">体育</option>
                <option value="4">音乐</option>
              </select>
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>

      <div class="layui-card-body">
        <table class="layui-hide" id="articlelist" lay-filter="articlelist" class="layui-table">
        </table>
        <script type="text/html" id="TopTool" >
          <div class="layui-btn-container" lay-filter="TopTool">
            <button class="layui-btn layui-btn-sm" lay-href="article/listform.html"> <i class="layui-icon layui-icon-add-1"></i>添加</button>
            <button class="layui-btn layui-btn-sm" lay-event="tonormal"><i class="layui-icon layui-icon-edit"></i>审核通过</button>
            <button class="layui-btn layui-btn-sm" lay-event="totrashlist"> <i class="layui-icon layui-icon-delete"></i>移至回收站</button>
            <button class="layui-btn layui-btn-sm" lay-event="deletelist"> <i class="layui-icon layui-icon-close-fill"></i>彻底删除</button>
          </div>
        </script>
        <script type="text/html" id="barDemo">
          <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-href="article/listform.html?editid={{d.article.id}}"><i class="layui-icon layui-icon-edit"></i>编辑</button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="totrash"><i class="layui-icon layui-icon-delete"></i>移至回收站</button>
          </div>
        </script>
      </div>
    </div>
  </div>

  <script src="../layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '../layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index']);

    layui.use(['table'], function(){
      var      table = layui.table
              ,setter = layui.setter
              ,$ = layui.jquery
              ,admin = layui.admin
              ,form = layui.form
              ,element = layui.element
              ,laytpl = layui.laytpl
              ,view = layui.view;


    table.render({
        elem: '#articlelist'
        , url: '/getarticlelist?date=0'
        , toolbar: '#TopTool'
        , title: '文章表'
        , totalRow: true
        , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        , cols: [[
          {checkbox: true, fixed: true}
          ,{field:'', title:'文章ID',  fixed: 'left', unresize: true, sort: true ,templet: '<a href="/article/{{d.id}}" target="_blank" class="layui-table-link">{{d.article.id}}</a>'}
          ,{field:'article.title', title:'文章标题', templet: '<a href="/article/{{d.id}}" target="_blank" class="layui-table-link">{{d.article.title}}</a>'}
          ,{field:'', title:'作者' , templet: '<a href="/article/{{d.id}}" target="_blank" class="layui-table-link">{{d.userInfo.nickname}}</a>'}
          ,{field:'', title:'分类' , templet: '<a href="/article/{{d.id}}" target="_blank" class="layui-table-link">{{d.classify.title}}</a>'}
          ,{field:'tags.title', title:'标签' , templet: '<a href="/article/{{d.id}}" target="_blank" class="layui-table-link">{{# d.tags.title }}</a>'}
          ,{field:'article.created', title:'创建日期',  templet: '#created'}
          ,{field:'article.status', title:'状态',templet: '#status'}
          ,{field:'article.comment_count', title:'评论数量', templet: '<a href="/article/{{d.id}}" target="_blank" class="layui-table-link">{{d.article.comment_count}}</a>'}
          ,{field:'article.modified', title:'最后修改时间', templet: '#modified'}
            ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
        ]]
        , page: true
      });
    //监听table
      table.on('tool(articlelist)', function(obj){
        var data = obj.data;
        if(obj.event === 'totrash'){
          layer.confirm('真的要移至回收站吗?', function(index){
            $(function(){
              $.post('/articleStatusToTrash.do?articleid=' + data.article.id);
              location.reload();
            })
            layer.close(index);
          });
        }
      });
      table.on('toolbar(articlelist)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        var checkStatus = table.checkStatus('articlelist')
                ,data = checkStatus.data;
        var IdArray = new Array();
        $.each(data,function(index,item){
          IdArray.push(item.article.id) ;
        });
        var IdList = JSON.stringify(IdArray);
        switch(obj.event){
          case 'tonormal':
            IdList = JSON.stringify(IdArray);
            $.ajax({
              url:'/articleStatusToNormal.do',
              type:'POST',//默认为get请求,这里设置为post请求
              contentType:'application/json',
              //当contentType为application/json,这里data参数需要使用json字符串
              //一定要是使用JSON.stringify这个去转化对象,否则后端也接收不到数据
              data:IdList,
              //dataType:'json',
              success:function(data, status){
                //若dataType设置json,并且后端正确返回json数据,则data为json对象
                //否则为字符串,一般不设置 dataType:'json',因为如果后端出错,没有
                //返回正确的json数据,那么当前方法就不会执行,新手不容易排查问题
                //data = JSON.parse(data);
                //alert(data.message);
                //prObject(data);
              }
            });
            location.reload();

            break;
          case 'totrashlist':

            layer.confirm('您确定要将这：'+ data.length + ' 个数据移入回收站吗?',function(index){
              var IdList = JSON.stringify(IdArray);
              $.ajax({
                url:'/articleStatusToTrash.do',
                type:'POST',//默认为get请求,这里设置为post请求
                contentType:'application/json;charset=UTF-8',
                traditional: true,
                //当contentType为application/json,这里data参数需要使用json字符串
                //一定要是使用JSON.stringify这个去转化对象,否则后端也接收不到数据
                data:IdList,
                //dataType:'json',
                success:function(data, status){
                  //若dataType设置json,并且后端正确返回json数据,则data为json对象
                  //否则为字符串,一般不设置 dataType:'json',因为如果后端出错,没有
                  //返回正确的json数据,那么当前方法就不会执行,新手不容易排查问题
                  //data = JSON.parse(data);
                  //alert(data.message);
                  //prObject(data);
                }
              });
              location.reload();
              layer.close(index);

            })
            break;
          case 'deletelist':
                  layer.confirm('您确定要将这：'+ data.length + ' 个数据彻底删除吗(该操作不可撤销)?',function(index){
                    $.ajax({
                      url:'/deleteArticle.do',
                      type:'POST',//默认为get请求,这里设置为post请求
                      contentType:'application/json;charset=UTF-8',
                      //当contentType为application/json,这里data参数需要使用json字符串
                      //一定要是使用JSON.stringify这个去转化对象,否则后端也接收不到数据
                      data:IdList,
                      //dataType:'json',
                      success:function(data, status){
                        //若dataType设置json,并且后端正确返回json数据,则data为json对象
                        //否则为字符串,一般不设置 dataType:'json',因为如果后端出错,没有
                        //返回正确的json数据,那么当前方法就不会执行,新手不容易排查问题
                        //data = JSON.parse(data);
                        //alert(data.message);
                        //prObject(data);
                      }
                    });
                    location.reload();
                    layer.close(index);

                  })
            break;
        };
      });
    });
  </script>
  <script>

  </script>
  <script src="/original/js/inttotime.js"></script>

  <script type="text/html" id="created">
    {{#
    var created = date(d.article.created);
    }}
    {{= created}}
  </script>
  <script type="text/html" id="modified">
    {{#
    var modified = date(d.article.modified);
    }}
    {{= modified}}
  </script>
  <script type="text/html" id="nickname">

  </script>
  <script type="text/html" id="status">
    {{#
    var str = " ";
    if(d.article.status=="normal"){str="已发布"}
    else if(d.article.status=="draft"){str="草稿箱"}
    else if(d.article.status=="trash"){str="垃圾箱"}
    }} {{= str }}
  </script>
  <script type="text/html" id="categorytitle">

  </script>
  <script type="text/html" id="tagstitle">

  </script>
  <script type="text/html" id="title">
    <a href="/article/{{d.id}}" target="_blank" class="layui-table-link">{{d.title}}</a>
  </script>
</body>
</html>
